package com.tgy.MyFlowable.workflow.listener;

import com.ctsi.workflow.util.BpmEventUtil;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.event.impl.FlowableProcessEventImpl;

/**
 * 全局流程结束监听器
 *
 * @version 1.0
 * @author: wang xiao xiang
 * @date: 2021/8/6 15:52
 */
@Slf4j
public class GlobalProcessCompletedListener implements FlowableEventListener {
    @Override
    public void onEvent(FlowableEvent flowableEvent) {
        FlowableProcessEventImpl flowableProcessEvent = (FlowableProcessEventImpl) flowableEvent;
        DelegateExecution execution = flowableProcessEvent.getExecution();
        String eventType = flowableProcessEvent.getType().name();
        //根据事件类型获取脚本并执行
        BpmEventUtil.getAndExecuteScript(execution, eventType);
        log.info(">>> 流程完成了........");
    }

    @Override
    public boolean isFailOnException() {
        return false;
    }

    @Override
    public boolean isFireOnTransactionLifecycleEvent() {
        return false;
    }

    @Override
    public String getOnTransaction() {
        return null;
    }
}
